<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Opts extends CI_Model 
{    
    function __construct()
    {
        parent::__construct();
    }
    
    function get_one($name)
    {
        /** 处理数据库验证 */
        $sql = "SELECT * FROM options WHERE `name` = ?";
        $quiry = $this->db->query($sql, $name);
       
        return ($quiry->num_rows() > 0)? $quiry->row_array() : '';
    }
    
    function get_options()
    {        
        return $this->db->get('options')->result_array();
    }
    
    public function set_options($options)
    {
        if($this->get_one($options['name']))
        {
            return $this->db->update('options', $options, array('name'=>$options['name']));
        }
        else
        {
            if($this->db->insert('options', $options))
                return 1;
            else
                return 0;
        }
            
        
    }
}